package report;
import java.io.FileOutputStream;
import java.io.OutputStream;
import java.sql.Connection;
import java.sql.SQLException;
import java.util.HashMap;
import java.util.Map;

import net.sf.jasperreports.engine.JasperCompileManager;
import net.sf.jasperreports.engine.JasperExportManager;
import net.sf.jasperreports.engine.JasperFillManager;
import net.sf.jasperreports.engine.JasperPrint;
import net.sf.jasperreports.engine.JasperReport;
import dao.GetCnn;

public class Sokhachhangmoitrongthang {
	public void Sokhmoitrongthang(String thang, String targetFolder,String source) throws SQLException{  
		   Connection cnn = GetCnn.getCnn();
		   try{
	             //String source1 = "D:\\workspace\\phantrang\\reports\\sokh.jrxml";
	             JasperReport jr = JasperCompileManager.compileReport(source);  

	             Map<String, Object> params = new HashMap<String, Object>();  
	             params.put("thang", thang);  
	             JasperPrint jp = JasperFillManager.fillReport(jr, params, cnn);  
	             OutputStream os = new FileOutputStream(targetFolder+"Baocao_khachhangmoi_thang_"+thang+".pdf");  
	             JasperExportManager.exportReportToPdfStream(jp,os);  

	             os.flush();  
	             os.close();  
	        } catch (Exception e) {  
	             e.printStackTrace();  
	        }finally{  
	             try{  
	                  if(cnn != null && !cnn.isClosed()){  
	                       cnn.close();  
	                  }  
	             }catch(Exception e){  
	                  e.printStackTrace();  
	             }  
	        }  
	   }  
	public void Sospbanduoctrongthang(String thang, String targetFolder,String source) throws SQLException{  
		   Connection cnn = GetCnn.getCnn();
		   try {  
	             //String source1 = "D:\\workspace\\phantrang\\reports\\sosp.jrxml";
	             JasperReport jr = JasperCompileManager.compileReport(source);  

	             Map<String, Object> params = new HashMap<String, Object>();  
	             params.put("thang", thang);  
	             JasperPrint jp = JasperFillManager.fillReport(jr, params, cnn);  
	             OutputStream os = new FileOutputStream(targetFolder+"Baocao_sanphambanduoc_thang_"+thang+".pdf");  
	             JasperExportManager.exportReportToPdfStream(jp,os);  

	             os.flush();  
	             os.close();  
	        } catch (Exception e) {  
	             e.printStackTrace();  
	        }finally{  
	             try{  
	                  if(cnn != null && !cnn.isClosed()){  
	                       cnn.close();  
	                  }  
	             }catch(Exception e){  
	                  e.printStackTrace();  
	             }  
	        }  
	   }  
	public void top10kh(String thang, String targetFolder,String source) throws SQLException{  
		   Connection cnn = GetCnn.getCnn();
		   try {  
	             //String source1 = "D:\\workspace\\phantrang\\reports\\sosp.jrxml";
	             JasperReport jr = JasperCompileManager.compileReport(source);  

	             Map<String, Object> params = new HashMap<String, Object>();  
	             params.put("thang", thang);  
	             JasperPrint jp = JasperFillManager.fillReport(jr, params, cnn);
	             OutputStream os = new FileOutputStream(targetFolder+"Baocao_top10khco_doanhsocao.pdf");  
	             JasperExportManager.exportReportToPdfStream(jp,os);  

	             os.flush();  
	             os.close();  
	        } catch (Exception e) {  
	             e.printStackTrace();  
	        }finally{  
	             try{  
	                  if(cnn != null && !cnn.isClosed()){  
	                       cnn.close();  
	                  }  
	             }catch(Exception e){  
	                  e.printStackTrace();  
	             }  
	        }  
	   }  
	public void hoadon(int mahd,String doanhso, String targetFolder,String source){
		Connection cnn = GetCnn.getCnn();
		   try {  
	             //String source1 = "D:\\workspace\\phantrang\\reports\\sosp.jrxml";
	             JasperReport jr = JasperCompileManager.compileReport(source);  

	             Map<String, Object> params = new HashMap<String, Object>();  
	             params.put("mahd", mahd);
	             params.put("doanhso", doanhso);
	             JasperPrint jp = JasperFillManager.fillReport(jr, params, cnn);  
	             OutputStream os = new FileOutputStream(targetFolder+"hoadon_"+mahd+".pdf");  
	             JasperExportManager.exportReportToPdfStream(jp,os);  

	             os.flush();  
	             os.close();  
	        } catch (Exception e) {  
	             e.printStackTrace();  
	        }finally{  
	             try{  
	                  if(cnn != null && !cnn.isClosed()){  
	                       cnn.close();  
	                  }  
	             }catch(Exception e){  
	                  e.printStackTrace();  
	             }  
	        } 
	}
}
